// src/utils/message.js
import { createApp } from 'vue'
import Message from '@/components/Message.vue'

let instance = null

export const initMessage = () => {
  if (instance) return
  
  const messageApp = createApp(Message)
  const node = document.createElement('div')
  document.body.appendChild(node)
  instance = messageApp.mount(node)
}

export const message = {
  info(content, duration = 3000) {
    instance?.addMessage(content, 'info', duration)
  },
  success(content, duration = 3000) {
    instance?.addMessage(content, 'success', duration)
  },
  warning(content, duration = 3000) {
    instance?.addMessage(content, 'warning', duration)
  },
  error(content, duration = 3000) {
    instance?.addMessage(content, 'error', duration)
  },
  closeAll() {
    // instance?.messages.value = []
  }
}